/*
 * Copyright 2003-2005 (c) Live Media Pty Ltd. <argot@einet.com.au> 
 *
 * This software is licensed under the Argot Public License 
 * which may be found in the file LICENSE distributed 
 * with this software.
 *
 * More information about this license can be found at
 * http://www.einet.com.au/License
 * 
 * The Developer of this software is Live Media Pty Ltd,
 * PO Box 4591, Melbourne 3001, Australia.  The license is subject 
 * to the law of Victoria, Australia, and subject to exclusive 
 * jurisdiction of the Victorian courts.
 */

#include "Types.h"

#include "TypeOutputStream.h"


/* Create a input structure */
void type_output_init( type_output_stream * out, type_map * map, argot_write ar, void * data )
{
	out->map = map;
	out->write_buffer = ar;
	out->data = data;
}

/* Destroy a input structure */
void type_output_destroy( type_output_stream * tis )
{
}

/* Set an error on the stream */
void type_output_set_error( type_output_stream * tis, int rc )
{
	/* FIXME */
}

/* Get/Check error on stream. Returns NULL if no error */
argot_error * type_output_get_error( type_output_stream * tis )
{
	return tis->error;
}

/* Read an object using the system id from the stream */
int type_output_write_object( type_output_stream * out,int id, void * object )
{
	typeWriter writer = type_map_get_writer( out->map, id );
	type_element * element = type_map_get_structure( out->map, id );
	return writer( out, object, element );		
}

/* Read an object using the object name */
int type_output_write_named_object( type_output_stream * out, type_name * name, void * object )
{
	int id = type_map_get_id( out->map, name );
	if ( id <= NOTYPE )
	{
		type_output_set_error( out, 10 );
		return TYPE_EOF;
	}
	
	typeWriter writer = type_map_get_writer( out->map, id );
	type_element * element = type_map_get_structure( out->map, id );
	return writer( out,  object, element );
}


